package com.kermel.andromeda.clock.format;

import junit.framework.TestCase;

import com.kermel.andromeda.test.fixture.TestClockSettings;

public class CurrentTimeFormatterTest extends TestCase {
    public static final long NORMAL_TIME_FIXTURE = 123456789;
    public static final long MILITARY_TIME_FIXTURE = 100000000;
    public static final String FORMAT_RESULT_NORMAL_TIME = "02:17:36 AM";
    public static final String FORMAT_RESULT_NORMAL_TIME_NO_SECONDS = "02:17 AM";
    public static final String FORMAT_RESULT_MILITARY_TIME = "19:46:40";
    public static final String FORMAT_RESULT_MILITARY_TIME_NO_SECONDS = "19:46";
    
    private CurrentTimeFormatter formatter;
    private TestClockSettings clockSettings;
    
    protected void setUp() throws Exception {
        super.setUp();
        
        clockSettings = new TestClockSettings();
        formatter = new CurrentTimeFormatter(clockSettings);
    }

    protected void tearDown() throws Exception {
        formatter = null;
        
        super.tearDown();
    }

    public void testThatFormatTimeAsStringReturnsNonNull() {
        long currentTime = -1;
        CharSequence result = formatter.formatTimeAsString(currentTime);
        assertNotNull(result);
    }
    
    public void testThatFormatTimeAsStringReturnsMilitaryTimeNoSeconds() {
        clockSettings.setMilitaryTime(true);
        
        CharSequence result = formatter.formatTimeAsString(MILITARY_TIME_FIXTURE);
        
        assertEquals(FORMAT_RESULT_MILITARY_TIME_NO_SECONDS, result);
    }
    
    public void testThatFormatTimeAsStringReturnsMilitaryTimeWithSeconds() {
        clockSettings.setMilitaryTime(true);
        clockSettings.setDisplaySeconds(true);
        
        CharSequence result = formatter.formatTimeAsString(MILITARY_TIME_FIXTURE);
        
        assertEquals(FORMAT_RESULT_MILITARY_TIME, result);
    }
    
    public void testThatFormatTimeAsStringReturnsNormalTimeIncludingSeconds() {
        clockSettings.setMilitaryTime(false);
        clockSettings.setDisplaySeconds(true);
        
        CharSequence result = formatter.formatTimeAsString(NORMAL_TIME_FIXTURE);
        
        assertEquals(FORMAT_RESULT_NORMAL_TIME, result);
    }
    
    public void testThatFormatTimeAsStringReturnsNormalTimeNoSeconds() {
        clockSettings.setDisplaySeconds(false);
        
        CharSequence result = formatter.formatTimeAsString(NORMAL_TIME_FIXTURE);
        
        assertEquals(FORMAT_RESULT_NORMAL_TIME_NO_SECONDS, result);
    }

    public void testThatFormatTimeAsStringReturnsSeconds() {
        clockSettings.setDisplaySeconds(true);
        
        CharSequence result = formatter.formatTimeAsString(NORMAL_TIME_FIXTURE);
        
        assertEquals(FORMAT_RESULT_NORMAL_TIME, result);
    }
    
    public void testThatFormatTimeAsStringReturnsNoSecondsUsingMilitaryTime() {
        clockSettings.setMilitaryTime(true);
        clockSettings.setDisplaySeconds(false);
        
        CharSequence result = formatter.formatTimeAsString(MILITARY_TIME_FIXTURE);
        
        assertEquals(FORMAT_RESULT_MILITARY_TIME_NO_SECONDS, result);
    }

    public void testThatFormatTimeAsStringReturnsSecondsMilitaryTime() {
        clockSettings.setMilitaryTime(true);
        clockSettings.setDisplaySeconds(true);
        
        CharSequence result = formatter.formatTimeAsString(MILITARY_TIME_FIXTURE);
        
        assertEquals(FORMAT_RESULT_MILITARY_TIME, result);
    }

}
